<template>
    <div class="dashboard-editor-container">
        <div>
            <el-breadcrumb separator="/" class="breadCrumb">
                <el-breadcrumb-item>{{$t('dashboard.homePage')}}</el-breadcrumb-item>
            </el-breadcrumb>
            <div class="boardTop">
                <panThumb style="float: left" :image="avatar"> {{ $t('dashboard.authority') }}:
                    <span class="pan-info-roles">admin</span>
                </panThumb>
                <div class="info-container">
                    <div class="display_name">{{userName}}</div>
                    <div class="info-wrapper">
                        <div class="info-item" @click="changePage('/taskHost/taskHostStatus')">
                            <div>
                                <countTo class="info-item-num" :startVal='0' :endVal='taskHostStatusNum' :duration='3800'></countTo>
                            </div>
                            <span class="info-item-text">{{ $t('dashboard.curRunningHost') }}</span>
                        </div>
                        <div class="info-item" @click="changePage('/taskRunner/taskRunnerConfig')">
                            <div>
                                <countTo class="info-item-num" :startVal='0' :endVal='taskRunnerConfigNum' :duration='3800'></countTo>
                            </div>
                            <span class="info-item-text">{{ $t('dashboard.curQueueTask') }}</span>
                        </div>
                        <div class="info-item" @click="changePage('/taskCroner/taskCronerConfig')">
                            <div>
                                <countTo class="info-item-num" :startVal='0' :endVal='taskCronerConfigNum' :duration='3800'></countTo>
                            </div>
                            <span class="info-item-text">{{ $t('dashboard.curTimedTask') }}</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="clearfix main-dashboard-container">
            <div class="chart-container">
                <!--<monthKpi style="border-bottom: 1px solid #DEE1E2;"
                          :articlesComplete='statisticsData.month_article_count'></monthKpi>-->
                <!--<articlesChart :listData='statisticsData.week_article'></articlesChart>-->
                <mixChart :timingSuccess="$t('dashboard.timingSuccessCount')" :timingFailure="$t('dashboard.timingFailureCount')" :runnerSuccess="$t('dashboard.runnerSuccessCount')" :runnerFailure="$t('dashboard.runnerFailureCount')"></mixChart>
            </div>
            <div class="recent-articles-container">
                <div class="recent-articles-title">{{ $t('dashboard.recentAlarm') }}</div>
                <div class="recent-articles-wrapper">
                    <div class="recent-articles-item" v-for="item in taskAlertInfoNotify">
                        <span class="recent-articles-status">{{item.contactMan}}</span>
                        <span class="recent-articles-content">
                            {{item.taskClass}}
                        </span>
                        <span class="recent-articles-time">{{item.contactInfoType}}</span>
                        <span class="recent-articles-way">{{formatDateTime(item.createDate)}}</span>
                        <el-button type="primary" size="mini" class="recent-articles-detail" @click="showDetails(item)">{{ $t('dashboard.details') }}</el-button>
                    </div>
                        <!--<div class="recent-articles-emptyTitle">最近没有报警通知</div>-->
                </div>
            </div>
        </div>
        <el-dialog :title="$t('dashboard.recentAlarm')" size="tiny" v-model="dialogDetails">
            <div class="alarmID">ID:<span>{{alarmForm.id}}</span></div>
            <el-form :model="alarmForm" label-width="100px">
                <el-row type="flex">
                    <el-col>
                        <el-form-item :label="$t('dashboard.taskClass')">
                            <el-input v-model="alarmForm.taskClass" readonly type="textarea" :rows="1"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row type="flex">
                    <el-col>
                        <el-form-item :label="$t('dashboard.createDate')">
                            <el-input v-model="alarmForm.createDate" readonly></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row type="flex">
                    <el-col>
                        <el-form-item :label="$t('dashboard.alertTitle')">
                            <el-input v-model="alarmForm.alertTitle" readonly></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row type="flex">
                    <el-col>
                        <el-form-item :label="$t('dashboard.alertBody')">
                            <el-input v-model="alarmForm.alertBody" readonly type="textarea" :rows="3"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </el-dialog>
    </div>
</template>
<script>
    import monthKpi from './monthKpi.vue';
    import articlesChart from './articlesChart.vue';
    import mixChart from './mixChart.vue';
    import panThumb from './panThumb/index.vue';
    import countTo from 'vue-count-to';
    import common from '../../assets/script/common';
    import {getCookie} from '../../assets/script/cookie.js'
    export default {
        name:'dashboard',
        components: { monthKpi, articlesChart, panThumb, countTo, mixChart },
        data() {
            return{
                userName:'',
                avatar:'../../../static/img/img.jpg',
                statisticsData: {
                    month_article_count: 28,
                    week_article: [
                        { count: 30, week: '201716' },
                        { count: 26, week: '201715' },
                        { count: 31, week: '201714' },
                        { count: 28, week: '201713' },
                        { count: 40, week: '201712' },
                        { count: 41, week: '201711' },
                        { count: 50, week: '201710' },
                        { count: 42, week: '201709' },
                        { count: 36, week: '201708' },
                        { count: 32, week: '201707' },
                        { count: 40, week: '201706' },
                        { count: 41, week: '201705' }
                    ]
                },
                taskCronerConfigNum: 0,
                taskHostStatusNum: 0,
                taskRunnerConfigNum: 0,
                taskAlertInfoNotify:[],
                formatDateTime(date) {
                    return common.formatDateTime(date,'ymd');
                },
                statisticMonth:'2017-05',
                dialogDetails:false,
                alarmForm:{
                    alertBody: "",
                    alertTitle: "",
                    createDate: "",
                    id: 0,
                    status: 0,
                    taskClass: ""
                }
            }
        },
        created() {
            this.getTaskAlertInfoNotify();
            this.getTaskDataNum();
        },
        methods:{
            getTaskAlertInfoNotify() {
                let self = this;
                self.userName = sessionStorage.getItem("username");
                common.getOtherAjax(self,'/api/homePage/taskAlertInfo',{},(res) => {
                    if(res.data.status === 401){
                        common.refreshToken(self, (token) => {
                            sessionStorage.setItem("token",token);
                            self.getTaskAlertInfoNotify();
                        });
                    }else{
                        self.taskAlertInfoNotify = res.data;
                    }
                });
            },
            getTaskDataNum() {
                let self = this;
                common.getOtherAjax(self,'/api/homePage/taskDataNum',{},(res) => {
                    if(res.data.status === 401){
                        common.refreshToken(self, (token) => {
                            sessionStorage.setItem("token",token);
                            self.getTaskDataNum();
                        });
                    }else{
                        self.taskCronerConfigNum = parseInt(res.data.taskCronerConfigNum);
                        self.taskHostStatusNum = parseInt(res.data.taskHostStatusNum);
                        self.taskRunnerConfigNum = parseInt(res.data.taskRunnerConfigNum);
                    }
                });
            },
            changePage (url) {
                this.$router.push({
                    path:url
                })
            },
            showDetails(item) {
                let self = this;
                self.dialogDetails = true;
                self.alarmForm = item;
                self.alarmForm.createDate = common.formatDateTime(item.createDate);
                if(item.status === 0)
                    self.alarmForm.status =  "正常";
            }
        }
    }
</script>
<style lang="stylus">
    .alarmID
        position absolute
        top 20px
        left 150px
    .dashboard-editor-container
        .boardTop
            height: 150px
            margin 30px 0
            .info-container
                float left
                margin-left 30px
                height: 150px
                .display_name
                    font-size: 48px
                    color: #212121
                    margin-top: 30px
                .info-wrapper
                    .info-item
                        cursor: pointer
                        display: inline-block
                        margin-right: 20px
                        .info-item-num
                            color: #212121
                            font-size: 24px
                            display: inline-block
                            padding-right: 5px
                        .info-item-text
                            color: #727272
                            font-size: 14px
                            padding-right: 5px
                            display: inline-block
    .main-dashboard-container
        position: relative
        border: 1px solid #DEE1E2
        height: 600px
        overflow: hidden
    .chart-container
        float: left
        position: absolute
        top: 0
        left: 0
        bottom: 0
        padding-right: 10px
        width: 50%
        border-right: 1px solid #DEE1E2
    .recent-articles-container {
        width: 50%;
        position: absolute;
        top: 0
        right: 0
        .recent-articles- {
            &title {
                font-size: 16px;
                color: #95A5A6;
                letter-spacing: 1px;
                padding-left: 15px;
                padding-bottom: 10px;
                border-bottom: 1px solid #DEE1E2;
            }
            &more {
                color: #2C3E50;
                font-size: 12px;
                float: right;
                margin-right: 25px;
                line-height: 40px;
                &:hover {
                    color: #3A71A8;
                }
            }
            &wrapper {
                padding: 0 20px 0 22px;
                .recent-articles- {
                    &item {
                        cursor: pointer;
                        padding: 16px 100px 16px 16px;
                        border-bottom: 1px solid #DEE1E2;
                        position: relative;
                        &:before {
                            content: "";
                            height: 104%;
                            width: 0px;
                            background: #20A0FF;
                            display: inline-block;
                            position: absolute;
                            opacity: 0;
                            left: 0px;
                            top: -2px;
                            transition: 0.3s ease all;
                        }
                        &:hover {
                            &:before {
                                opacity: 1;
                                width: 3px;
                            }
                        }
                    }
                    &status {
                        display: inline-block;
                        color: #9B9B9B;
                        padding-right: 6px;
                    }
                    &content {
                        margin-left: 30px;
                        font-size: 13px;
                        color: #2C3E50;
                        &:hover {
                            color: #3A71A8;
                        }
                    }
                    &way {
                        font-size: 12px;
                        color: #9B9B9B;
                        position: absolute;
                        top: 20px;
                        right: 100px;
                    }
                    &time {
                        font-size: 12px;
                        color: #9B9B9B;
                        margin-left: 30px;
                    }
                    &detail{
                        position: absolute;
                        top: 16px;
                        right: 16px;
                    }
                }
            }
        }

    }
</style>
